function table.val_to_str ( v )
  if "string" == type( v ) then
    v = string.gsub( v, "\n", "\\n" )
    if string.match( string.gsub(v,"[^'\"]",""), '^"+$' ) then
      return "'" .. v .. "'"
    end
    return '"' .. string.gsub(v,'"', '\\"' ) .. '"'
  else
    return "table" == type( v ) and table.tostring( v ) or
      tostring( v )
  end
end

function table.key_to_str ( k )
  if "string" == type( k ) and string.match( k, "^[_%a][_%a%d]*$" ) then
    return k
  else
    return "[" .. table.val_to_str( k ) .. "]"
  end
end

function table.tostring( tbl )
  local result, done = {}, {}
  for k, v in ipairs( tbl ) do
    table.insert( result, table.val_to_str( v ) )
    done[ k ] = true
  end
  for k, v in pairs( tbl ) do
    if not done[ k ] then
      table.insert( result,
        table.key_to_str( k ) .. "=" .. table.val_to_str( v ) )
    end
  end
  return "{" .. table.concat( result, "," ) .. "}"
end

function round(num, idp)
  local mult = 10^(idp or 0)
  return math.floor(num * mult + 0.5) / mult
end

function compute_dm(dr, d, d_mod)

	if not dr or not d or not d_mod then
		print("COMPUTE_DM insufficient parameters")		
		return nil
	end
	
	return (dr - ((dr + d) / 2))/d_mod

end

function check_memory()
	
	local a = MOAISim:getHistogram()
	print("#### MEMORY INFO ###")
	print("#### HISTOGRAM ###")
	for key, value in pairs(a) do
		
		print(key, value)
		
	
	end
	print("#### LUA OBJECT COUNT ####")
	print(MOAISim:getLuaObjectCount())
	local b = MOAISim:getMemoryUsage()
	print("#### MEMORY USAGE ####")
	for key, value in pairs(b) do
		
		print(key, value)
	
	end
	print("#### ESTIMATED FPS : " .. MOAISim:getPerformance() .. " ####")
	print("#### FRAME PASS IN SEC: " .. MOAISim:getStep() .. " ####")
	

end

typeof = type